﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：72a7c2bd-ab5b-4f1e-9bec-eb5432ceb1e6
 * 文件名：PartContainer
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/6/24 9:54:49
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
///
/// </summary>
public sealed class PartContainer : ContainerControlBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    internal PartContainer()
    {
    }

    public override string Title { get; set; }
    public override List<ControlBase> Children { get; internal set; }
    public override string Id { get; set; }

    public override string ConverToHtml()
    {
        StringBuilder sb = new StringBuilder();
        sb.AppendLine($"<h{HLevel} id=\"{Title}\">");

        //sb.AppendLine($"<a class=\"header-anchor vp-link\" style=\"background-color: transparent;touch-action: manipulation;font-weight: 500;text-decoration: inherit;color: #409eff;position: absolute;margin-top: .125em;margin-left: -.87em;padding-right: .23em;font-size: .85em;opacity: 0;transition: opacity 0.3s;display: inline-flex;align-items: center;white-space: nowrap;\" href=\"#{Title}\" >#</a> ");
        sb.AppendLine($"<a class=\"header-anchor vp-link\"  href=\"#{Title}\" >#</a> ");


        //sb.AppendLine($"<a class=\"header-anchor vp-link\" href=\"#{Title}\" aria-hidden=\"true\">#</a> ");
        sb.AppendLine($"{Title}");
        sb.AppendLine($"</h{HLevel}>");

        sb.AppendLine($"<div id=\"{Id}\" style=\"margin-top: 30px;\" >");
        foreach (var item in Children)
        {
            sb.AppendLine(item.ConverToHtml());
        }
        sb.AppendLine($"</div >");

        return sb.ToString();
    }


    /// <summary>
    /// h显示层级
    /// </summary>
    internal int HLevel { get; set; }
}

public static partial class App
{
    /// <summary>
    /// 创建Part容器
    /// </summary>
    /// <param name="title"></param>
    /// <param name="child"></param>
    /// <param name="hLevel"></param>
    /// <returns></returns>
    public static PartContainer CreatePartContainer(string title, Action<List<ControlBase>> child,int hLevel=2)
    {
        PartContainer page = new PartContainer()
        {
            Id = title,
            Title = title,
            HLevel = hLevel
        };

        page.Children = new List<ControlBase>();

        child?.Invoke(page.Children);

        return page;
    }
}